﻿/*
#------------------------------------------------------------------------------
#-- Program Name:	[dbo].[fnMSX_get_backup_server]
#-- Purpose:		Extract the server name from a UNC path to determine the
#--					server that the backups are writing onto
#--	Last Update:	07/31/2012
#--					For a complete history - please review comments in Version
#--					Control.
#------------------------------------------------------------------------------
*/
CREATE FUNCTION [dbo].[fnMSX_get_backup_server]
(
	@backup_directory				varchar(255)
)
RETURNS varchar(20)
AS
BEGIN
	RETURN	UPPER(CASE	WHEN LEFT(@backup_directory, 2)='\\' 
							THEN substring(@backup_directory, 3, CHARINDEX('\', @backup_directory, 3) - 3)
						ELSE NULL
						END)
END
